/**
 * Copyright (c) 2012-2014, Yang Yang <cntototo@gmail.com>
 *
 * This software may be distributed under the terms of the New BSD License.
 * See README for more details.
 *
 * wsc_def.h contains definitions from WSC2.0 spec.
 */

#ifndef WSC_DEF_H
#define WSC_DEF_H

/** WSC protocol time (in seconds) */
#define WSC_PROTOCOL_TIMEOUT 120

/** PBC walk time (in seconds) */
#define WSC_PBC_WALK_TIMEOUT 120

/** Retransmission time (in seconds) */
#define WSC_RETRANSMIT_TIMEOUT 5

/** Individual message processing time (in seconds) */
#define WSC_MSG_TIMEOUT 15

/** WSC OUI */
#define WSC_OUI 0x0050F204

/** EAP-WSC op-code */
enum wsc_eap_wsc_op_code {
	OP_CODE_WSC_START = 0x01,
	OP_CODE_WSC_ACK = 0x02,
	OP_CODE_WSC_NACK = 0x03,
	OP_CODE_WSC_MSG = 0x04,
	OP_CODE_WSC_DONE = 0x05,
	OP_CODE_WSC_FRAG_ACK = 0x06
};

/** WSC2.0 attribute type */
enum wsc_attr_type {
	YPATTR_T_AP_CHANNEL = 0x1001,
	ATTR_T_ASSOC_STATE = 0x1002,
	ATTR_T_AUTH_TYPE = 0x1003,
	ATTR_T_AUTH_TYPE_FLAGS = 0x1004,
	ATTR_T_AUTHENTICATOR = 0x1005,
	ATTR_T_CONFIG_METHODS = 0x1008,
	ATTR_T_CONFIG_ERROR = 0x1009,
	ATTR_T_CONFIRM_URL4 = 0x100A,
	ATTR_T_CONFIRM_URL6 = 0x100B,
	ATTR_T_CONN_TYPE = 0x100C,
	ATTR_T_CONN_TYPE_FLAGS = 0x100D,
	ATTR_T_CRED = 0x100E,
	ATTR_T_ENCR_TYPE = 0x100F,
	ATTR_T_ENCR_TYPE_FLAGS = 0x1010,
	ATTR_T_DEV_NAME = 0x1011,
	ATTR_T_DEV_PASSWORD_ID = 0x1012,
	ATTR_T_E_HASH1 = 0x1014,
	ATTR_T_E_HASH2 = 0x1015,
	ATTR_T_E_SNONCE1 = 0x1016,
	ATTR_T_E_SNONCE2 = 0x1017,
	ATTR_T_ENCR_SETTINGS = 0x1018,
	ATTR_T_ENROLLEE_NONCE = 0x101A,
	ATTR_T_FEATURE_ID = 0x101B,
	ATTR_T_IDENTITY = 0x101C,
	ATTR_T_IDENTITY_PROOF = 0x101D,
	ATTR_T_KEY_WRAP_AUTH = 0x101E,
	ATTR_T_KEY_ID = 0x101F,
	ATTR_T_MAC_ADDR = 0x1020,
	ATTR_T_MANUFACTURER = 0x1021,
	ATTR_T_MSG_TYPE = 0x1022,
	ATTR_T_MODEL_NAME = 0x1023,
	ATTR_T_MODEL_NUMBER = 0x1024,
	ATTR_T_NETWORK_INDEX = 0x1026,
	ATTR_T_NETWORK_KEY = 0x1027,
	ATTR_T_NETWORK_KEY_INDEX = 0x1028,
	ATTR_T_NEW_DEV_NAME = 0x1029,
	ATTR_T_NEW_PASSWORD = 0x102A,
	ATTR_T_OOB_DEV_PASSWORD = 0x102C,
	ATTR_T_OS_VERSION = 0x102D,
	ATTR_T_POWER_LEVEL = 0x102F,
	ATTR_T_PSK_CURRENT = 0x1030,
	ATTR_T_PSK_MAX = 0x1031,
	ATTR_T_PUBLIC_KEY = 0x1032,
	ATTR_T_RADIO_ENABLED = 0x1033,
	ATTR_T_REBOOT = 0x1034,
	ATTR_T_REGISTRAR_CURRENT = 0x1035,
	ATTR_T_REGISTRAR_ESTABLISHED = 0x1036,
	ATTR_T_REGISTRAR_LIST = 0x1037,
	ATTR_T_REGISTRAR_MAX = 0x1038,
	ATTR_T_REGISTRAR_NONCE = 0x1039,
	ATTR_T_REQUEST_TYPE = 0x103A,
	ATTR_T_RESPONSE_TYPE = 0x103B,
	ATTR_T_RF_BANDS = 0x103C,
	ATTR_T_R_HASH1 = 0x103D,
	ATTR_T_R_HASH2 = 0x103E,
	ATTR_T_R_SNONCE1 = 0x103F,
	ATTR_T_R_SNONCE2 = 0x1040,
	ATTR_T_SELECTED_REGISTRAR = 0x1041,
	ATTR_T_SERIAL_NUMBER = 0x1042,
	ATTR_T_WSC_STATE = 0x1044,
	ATTR_T_SSID = 0x1045,
	ATTR_T_TOTAL_NETWORKS = 0x1046,
	ATTR_T_UUID_E = 0x1047,
	ATTR_T_UUID_R = 0x1048,
	ATTR_T_VENDOR_EXT = 0x1049,
	ATTR_T_VERSION = 0x104A,
	ATTR_T_X509_CERT_REQUEST = 0x104B,
	ATTR_T_X509_CERT = 0x104C,
	ATTR_T_EAP_IDENTITY = 0x104D,
	ATTR_T_MSG_COUNTER = 0x104E,
	ATTR_T_PUBLIC_KEY_HASH = 0x104F,
	ATTR_T_REKEY_KEY = 0x1050,
	ATTR_T_KEY_LIFETIME = 0x1051,
	ATTR_T_PERMITTED_CONFIG_METHODS = 0x1052,
	ATTR_T_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053,
	ATTR_T_PRIMARY_DEV_TYPE = 0x1054,
	ATTR_T_SECONDARY_DEV_TYPE_LIST = 0x1055,
	ATTR_T_PORTABLE_DEV = 0x1056,
	ATTR_T_AP_SETUP_LOCKED = 0x1057,
	ATTR_T_APPLICATION_EXT = 0x1058,
	ATTR_T_EAP_TYPE = 0x1059,
	ATTR_T_IV = 0x1060,
	ATTR_T_KEY_PROVIDED_AUTO = 0x1061,
	ATTR_T_802_1X_ENABLED = 0x1062,
	ATTR_T_APPSESSIONKEY = 0x1063,
	ATTR_T_WEPTRANSMITKEY = 0x1064,
	ATTR_T_REQUESTED_DEV_TYPE = 0x106A
};

/** WSC2.0 attribute length */
enum wsc_attr_len {
	ATTR_L_AP_CHANNEL = 2,
	ATTR_L_ASSOC_STATE = 2,
	ATTR_L_AUTH_TYPE = 2,
	ATTR_L_AUTH_TYPE_FLAGS = 2,
	ATTR_L_AUTHENTICATOR = 8,
	ATTR_L_CONFIG_METHODS = 2,
	ATTR_L_CONFIG_ERROR = 2,
	ATTR_L_CONFIRM_URL4 = 64,
	ATTR_L_CONFIRM_URL6 = 76,
	ATTR_L_CONN_TYPE = 1,
	ATTR_L_CONN_TYPE_FLAGS = 1,
	ATTR_L_CRED = 0xFF,
	ATTR_L_ENCR_TYPE = 2,
	ATTR_L_ENCR_TYPE_FLAGS = 2,
	ATTR_L_DEV_NAME = 32,
	ATTR_L_DEV_PASSWORD_ID = 2,
	ATTR_L_E_HASH1 = 32,
	ATTR_L_E_HASH2 = 32,
	ATTR_L_E_SNONCE1 = 16,
	ATTR_L_E_SNONCE2 = 16,
	ATTR_L_ENCR_SETTINGS = 0xFF,
	ATTR_L_ENROLLEE_NONCE = 16,
	ATTR_L_FEATURE_ID = 4,
	ATTR_L_IDENTITY = 80,
	ATTR_L_IDENTITY_PROOF = 0xFF,
	ATTR_L_KEY_WRAP_AUTH = 8,
	ATTR_L_KEY_ID = 16,
	ATTR_L_MAC_ADDR = 6,
	ATTR_L_MANUFACTURER = 64,
	ATTR_L_MSG_TYPE = 1,
	ATTR_L_MODEL_NAME = 32,
	ATTR_L_MODEL_NUMBER = 32,
	ATTR_L_NETWORK_INDEX = 1,
	ATTR_L_NETWORK_KEY = 64,
	ATTR_L_NETWORK_KEY_INDEX = 1,
	ATTR_L_NEW_DEV_NAME = 32,
	ATTR_L_NEW_PASSWORD = 64,
	ATTR_L_OOB_DEV_PASSWORD = 58,
	ATTR_L_OS_VERSION = 4,
	ATTR_L_POWER_LEVEL = 1,
	ATTR_L_PSK_CURRENT = 1,
	ATTR_L_PSK_MAX = 1,
	ATTR_L_PUBLIC_KEY = 192,
	ATTR_L_RADIO_ENABLED = 1,
	ATTR_L_REBOOT = 1,
	ATTR_L_REGISTRAR_CURRENT = 1,
	ATTR_L_REGISTRAR_ESTABLISHED = 1,
	ATTR_L_REGISTRAR_LIST = 512,
	ATTR_L_REGISTRAR_MAX = 1,
	ATTR_L_REGISTRAR_NONCE = 16,
	ATTR_L_REQUEST_TYPE = 1,
	ATTR_L_RESPONSE_TYPE = 1,
	ATTR_L_RF_BANDS = 1,
	ATTR_L_R_HASH1 = 32,
	ATTR_L_R_HASH2 = 32,
	ATTR_L_R_SNONCE1 = 16,
	ATTR_L_R_SNONCE2 = 16,
	ATTR_L_SELECTED_REGISTRAR = 1,
	ATTR_L_SERIAL_NUMBER = 32,
	ATTR_L_WSC_STATE = 1,
	ATTR_L_SSID = 32,
	ATTR_L_TOTAL_NETWORKS = 1,
	ATTR_L_UUID_E = 16,
	ATTR_L_UUID_R = 16,
	ATTR_L_VENDOR_EXT = 1024,
	ATTR_L_VERSION = 1,
	ATTR_L_X509_CERT_REQUEST = 0xFF,
	ATTR_L_X509_CERT = 0xFF,
	ATTR_L_EAP_IDENTITY = 64,
	ATTR_L_MSG_COUNTER = 8,
	ATTR_L_PUBLIC_KEY_HASH = 20,
	ATTR_L_REKEY_KEY = 32,
	ATTR_L_KEY_LIFETIME = 4,
	ATTR_L_PERMITTED_CONFIG_METHODS = 2,
	ATTR_L_SELECTED_REGISTRAR_CONFIG_METHODS = 2,
	ATTR_L_PRIMARY_DEV_TYPE = 8,
	ATTR_L_SECONDARY_DEV_TYPE_LIST = 128,
	ATTR_L_PORTABLE_DEV = 1,
	ATTR_L_AP_SETUP_LOCKED = 1,
	ATTR_L_APPLICATION_EXT = 512,
	ATTR_L_EAP_TYPE = 8,
	ATTR_L_IV = 32,
	ATTR_L_KEY_PROVIDED_AUTO = 1,
	ATTR_L_802_1X_ENABLED = 1,
	ATTR_L_APPSESSIONKEY = 128,
	ATTR_L_WEPTRANSMITKEY = 1,
	ATTR_L_REQUESTED_DEV_TYPE = 8
};

/** WFA vendor extension subelements */
enum wsc_wfa_vendor_ext_subelem_type {
	WFA_SUBELEM_T_VERSION2 = 0x00,
	WFA_SUBELEM_T_AUTHORIZEDMACS = 0x01,
	WFA_SUBELEM_T_NETWORK_KEY_SHAREABLE = 0x02,
	WFA_SUBELEM_T_REQUEST_TO_POLL = 0x03,
	WFA_SUBELEM_T_SETTINGS_DELAY_TIME = 0x04
};

enum wsc_wfa_vendor_ext_subelem_len {
	WFA_SUBELEM_L_VERSION2 = 1,
	WFA_SUBELEM_L_AUTHORIZEDMACS = 30,
	WFA_SUBELEM_L_NETWORK_KEY_SHAREABLE = 1,
	WFA_SUBELEM_L_REQUEST_TO_POLL = 1,
	WFA_SUBELEM_L_SETTINGS_DELAY_TIME = 1
};

/** Associate state */
enum wsc_assoc_state {
	ASSOC_STATE_NOT_ASSOCIATED = 0,
	ASSOC_STATE_CONN_SUCCESS = 1,
	ASSOC_STATE_CONFIG_FAILURE = 2,
	ASSOC_STATE_ASSOC_FAILURE = 3,
	ASSOC_STATE_IP_FAILURE = 4
};

/** Authentication type */
enum wsc_auth_type {
	AUTH_TYPE_OPEN = 0x0001,
	AUTH_TYPE_WPAPSK = 0x0002,
	AUTH_TYPE_SHARED = 0x0004,
	AUTH_TYPE_WPA = 0x0008,
	AUTH_TYPE_WPA2 = 0x0010,
	AUTH_TYPE_WPA2PSK = 0x0020
};
#define WSC_AUTH_TYPES (AUTH_TYPE_OPEN | AUTH_TYPE_WPAPSK | AUTH_TYPE_SHARED | \
			AUTH_TYPE_WPA | AUTH_TYPE_WPA2 | AUTH_TYPE_WPA2PSK)

/** Configuration methods */
enum wsc_config_methods {
	CONFIG_METHODS_USBA = 0x0001, /* Deprecated */
	CONFIG_METHODS_ETHERNET = 0x0002, /* Deprecated*/
	CONFIG_METHODS_LABEL = 0x0004,
	CONFIG_METHODS_DISPLAY = 0x0008,
	CONFIG_METHODS_EXT_NFC_TOKEN = 0x0010,
	CONFIG_METHODS_INT_NFC_TOKEN = 0x0020,
	CONFIG_METHODS_NFC_INTEFACE = 0x0040,
	CONFIG_METHODS_PUSHBUTTON = 0x0080,
	CONFIG_METHODS_KEYPAD = 0x0100,
	CONFIG_METHODS_VIRT_PUSHBUTTON = 0x0280,
	CONFIG_METHODS_PHY_PUSHBUTTON = 0x0480,
	CONFIG_METHODS_VIRT_DISPLAY = 0x2008,
	CONFIG_METHODS_PHY_DISPLAY = 0x4008
};

/** Configuration error */
enum wsc_config_error {
	CONFIG_ERROR_NO_ERROR = 0,
	CONFIG_ERROR_OOB_IFACE_READ_ERROR = 1,
	CONFIG_ERROR_DECRYPTION_CRC_FAILURE = 2,
	CONFIG_ERROR_2_4_CHAN_NOT_SUPPORTED = 3,
	CONFIG_ERROR_5_0_CHAN_NOT_SUPPORTED = 4,
	CONFIG_ERROR_SIGNAL_TOO_WEAK = 5, /* Deprecated */
	CONFIG_ERROR_NETWORK_AUTH_FAILURE = 6, /* Deprecated */
	CONFIG_ERROR_NETWORK_ASSOC_FAILURE = 7, /* Deprecated */
	CONFIG_ERROR_NO_DHCP_RESPONSE = 8, /* Deprecated */
	CONFIG_ERROR_FAILED_DHCP_CONFIG = 9, /* Deprecated */
	CONFIG_ERROR_IP_ADDR_CONFLICT = 10, /* Deprecated */
	CONFIG_ERROR_COULD_NOT_CONN_TO_REGISTRAR = 11,
	CONFIG_ERROR_MULTIPLE_PBC_DETECTED = 12,
	CONFIG_ERROR_ROGUE_ACTIVITY_SUSPECTED = 13,
	CONFIG_ERROR_DEV_BUSY = 14,
	CONFIG_ERROR_SETUP_LOCKED = 15,
	CONFIG_ERROR_MSG_TIMEOUT = 16,
	CONFIG_ERROR_REGISTRATION_SESSION_TIMEOUT = 17,
	CONFIG_ERROR_DEV_PASSWORD_AUTH_FAILURE = 18
};

/** Connection type */
enum wsc_conn_type {
	CONN_TYPE_ESS = 0x1,
	CONN_TYPE_IBSS = 0x2
};

/** Device password id */
enum wsc_dev_password_id {
	DEV_PASSWORD_ID_DEFAULT = 0x0000, /* PIN */
	DEV_PASSWORD_ID_USER_SPECIFIED = 0x0001,
	DEV_PASSWORD_ID_MACHINE_SPECIFIED = 0x0002,
	DEV_PASSWORD_ID_REKEY = 0x0003,
	DEV_PASSWORD_ID_PUSHBUTTON = 0x0004,
	DEV_PASSWORD_ID_REGISTRAR_SPECIFIED = 0x0005
};

/** Encryption type */
enum wsc_encr_type {
	ENCR_TYPE_NONE = 0x0001,
	ENCR_TYPE_WEP = 0x0002,
	ENCR_TYPE_TKIP = 0x0004,
	ENCR_TYPE_AES = 0x0008
};
#define WSC_ENCR_TYPES (ENCR_TYPE_NONE | ENCR_TYPE_WEP | ENCR_TYPE_TKIP | \
			ENCR_TYPE_AES)

/** Message type */
enum wsc_msg_type {
	MSG_TYPE_BEACON = 0x01,
	MSG_TYPE_PROBE_REQUEST = 0x02,
	MSG_TYPE_PROBE_RESPONSE = 0x03,
	MSG_TYPE_M1 = 0x04,
	MSG_TYPE_M2 = 0x05,
	MSG_TYPE_M2D = 0x06,
	MSG_TYPE_M3 = 0x07,
	MSG_TYPE_M4 = 0x08,
	MSG_TYPE_M5 = 0x09,
	MSG_TYPE_M6 = 0x0A,
	MSG_TYPE_M7 = 0x0B,
	MSG_TYPE_M8 = 0x0C,
	MSG_TYPE_WSC_ACK = 0x0D,
	MSG_TYPE_WSC_NACK = 0x0E,
	MSG_TYPE_WSC_DONE = 0x0F
};

/** Primary device type: category */
enum wsc_pdt_category {
	PDT_COMPUTER = 1,
	PDT_INPUT_DEV = 2,
	PDT_PRINTER = 3,
	PDT_CAMERA = 4,
	PDT_STORAGE = 5,
	PDT_NETWORK_INFRA = 6,
	PDT_DISPLAY = 7,
	PDT_MULTIMEDIA_DEV = 8,
	PDT_GAMING_DEV = 9,
	PDT_PHONE = 10,
	PDT_AUDIO_DEV = 11
};

/** Primary device type: subcategory */
enum wsc_pdt_subcategory {
	/** Computer */
	PDT_SUB_PC = 1,
	PDT_SUB_SERVER = 2,
	PDT_SUB_MEDIA_CENTER = 3,
	PDT_SUB_ULTRA_MOBILE_PC = 4,
	PDT_SUB_NOTEBOOK = 5,
	PDT_SUB_DESKTOP = 6,
	PDT_SUB_MID = 7,
	PDT_SUB_NETBOOK = 8,

	/** Input device */
	PDT_SUB_KEYBOARD = 1,
	PDT_SUB_MOUSE = 2,
	PDT_SUB_JOYSTICK = 3,
	PDT_SUB_TRACKBALL = 4,
	PDT_SUB_GAMING_CONTROLLER = 5,
	PDT_SUB_REMOTE = 6,
	PDT_SUB_TOUCHSCREEN = 7,
	PDT_SUB_BIOMETRIC_READER = 8,
	PDT_SUB_BARCODE_READER = 9,

	/** Printer */
	PDT_SUB_PRINTER = 1,
	PDT_SUB_SCANNER = 2,
	PDT_SUB_FAX = 3,
	PDT_SUB_COPIER = 4,
	PDT_SUB_ALL_IN_ONE = 5,

	/** Camera */
	PDT_SUB_DIGITAL_STILL_CAMERA = 1,
	PDT_SUB_VIDEO_CAMERA = 2,
	PDT_SUB_WEB_CAMERA = 3,
	PDT_SUB_SECURITY_CAMERA = 4,

	/** Storage */
	PDT_SUB_NAS = 1,

	/** Network infrastructure */
	PDT_SUB_AP = 1,
	PDT_SUB_ROUTER = 2,
	PDT_SUB_SWITCH = 3,
	PDT_SUB_GATEWAY = 4,
	PDT_SUB_BRIDGE = 5,

	/** Display */
	PDT_SUB_TV = 1,
	PDT_SUB_ELEC_PIC_FRAME = 2,
	PDT_SUB_PROJECTOR = 3,
	PDT_SUB_MONITOR = 4,

	/** Multimedia device */
	PDT_SUB_DAR = 1,
	PDT_SUB_PVR = 2,
	PDT_SUB_MCX = 3,
	PDT_SUB_SETTOP_BOX = 4,
	PDT_SUB_MEDIA_SERVER = 5,
	PDT_SUB_PORTABLE_VIDEO_PLAYER = 6,

	/** Gaming device */
	PDT_SUB_XBOX = 1,
	PDT_SUB_XBOX360 = 2,
	PDT_SUB_PLAYSTATION = 3,
	PDT_SUB_GAME_CONSOLE = 4,
	PDT_SUB_PORTABLE_GAMING_DEVICE = 5,

	/** Telephone */
	PDT_SUB_WINDOWS_MOBILE = 1,
	PDT_SUB_SINGLE_MODE = 2,
	PDT_SUB_DUAL_MODE = 3,
	PDT_SUB_SMARTPHONE_SINGLE_MODE = 4,
	PDT_SUB_SMARTPHONE_DUAL_MODE = 5,

	/** Audio device */
	PDT_SUB_AUDIO_TUNER = 1,
	PDT_SUB_SPEAKER = 2,
	PDT_SUB_PMP = 3,
	PDT_SUB_HEADSET = 4,
	PDT_SUB_HEADPHONE = 5,
	PDT_SUB_MICROPHONE = 6,
	PDT_SUB_HOME_THEATER_SYSTEM = 7
};

/** Request type */
enum wsc_request_type {
	REQUEST_TYPE_ENROLLEE_INFO = 0x00,
	REQUEST_TYPE_ENROLEE = 0x01,
	REQUEST_TYPE_REGISTRAR = 0x02,
	REQUEST_TYPE_WLAN_MANAGER_REGISTRAR = 0x03
};

/** Response type */
enum wsc_response_type {
	RESPONSE_TYPE_ENROLLEE_INFO = 0x00,
	RESPONSE_TYPE_ENROLLEE = 0x01,
	RESPONSE_TYPE_REGISTRAR = 0x02,
	RESPONSE_TYPE_AP = 0x03
};

/** RF band */
enum wsc_rf_band {
	RF_BAND_2_4_GHZ = 0x01,
	RF_BAND_5_0_GHZ = 0x02
};

/** WSC state */
enum wsc_wsc_state {
	WSC_STATE_NOT_CONFIGURED = 0x01,
	WSC_STATE_CONFIGURED = 0x02
};

#endif /* WSC_DEF_H */
